<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateArticlesTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('article', ['id' => 'id', 'comment' => '文章表']);
        $table->addColumn('title', 'string', ['limit' => 255, 'comment' => '标题'])
            ->addColumn('author', 'string', ['limit' => 255, 'comment' => '作者'])
            ->addColumn('sort', 'integer', ['default' => 0, 'comment' => '排序'])
            ->addColumn('views', 'integer', ['default' => 0, 'comment' => '阅读量'])
            ->addColumn('content', 'text', ['comment' => '内容'])
            ->addColumn('attachment', 'string', ['limit' => 500, 'null' => true, 'comment' => '附件'])
            ->addColumn('article_category_id', 'integer', ['comment' => '分类id'])
            ->addColumn('is_home_display', 'boolean', ['default' => false, 'comment' => '是否首页显示'])
            ->addIndex(['title'], ['name' => 'idx_title'])
            ->addIndex(['author'], ['name' => 'idx_author'])
            ->addTimestamps()
            ->addSoftDelete()
            ->create();
    }
}
